/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.hpvas.control;

import edu.hpvas.persistence.dao.AppointmentDAO;
import edu.hpvas.persistence.dao.MedicalRecordDAO;
import edu.hpvas.persistence.dao.PetDAO;
import edu.hpvas.persistence.entity.Appointment;
import edu.hpvas.persistence.entity.MedicalRecord;
import edu.hpvas.persistence.entity.Owner;
import edu.hpvas.persistence.entity.Pet;
import edu.hpvas.persistence.entity.Veterinarian;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author sony
 */
public class AppointmentController {
    
    PetDAO petDao = new PetDAO();
    AppointmentDAO appointDao= new AppointmentDAO();
    MedicalRecordDAO medicalDao = new MedicalRecordDAO();
    
    public int getAppointmentCharge(Integer IdOwner){
        ArrayList pets = new ArrayList();
        Appointment appoint= new Appointment();
        List<Appointment> appointments;
        MedicalRecord medical = new MedicalRecord();
        List<Pet> petsList =  petDao.findPetEntities();
        int value=0;
        for(Pet p:petsList){
            if( p.getIdOwner() != null && p.getIdOwner().getId().intValue()==IdOwner.intValue()){
                medical= p.getIdMedicalRecord();
                for(Appointment a:medical.getAppointmentCollection()){
                    value+=a.getCharge().intValue();
                }
            }
        }
        return value;
    }
    public boolean setAppointment(Appointment appoint, Veterinarian veterinarian, Pet pet){
        
        List<Appointment> appoints = appointDao.findAppointmentEntities();
        int idAp=1;
        for(Appointment ap: appoints){
            if(ap.getId().intValue()!=idAp){
                break;
            }
            idAp++;
        }
        appoint.setId(idAp);
        appoint.setIdMedicalRecord(pet.getIdMedicalRecord());
        appoint.setIdVeterinarian(veterinarian);
        appoint.setNotes("");
        try {
            appointDao.create(appoint);
            return true;
        } catch (Exception ex) {
            Logger.getLogger(AppointmentController.class.getName()).log(Level.SEVERE, null, ex);
            return false;
        }
        
    }
    public ArrayList<Appointment> getByVet(Veterinarian vet){
        return new ArrayList<>(appointDao.findAppointmentByVet(vet));
    }
}
